package cn.chendd.api.client;

import cn.chendd.api.vo.ComplexVo;
import feign.Response;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.awt.*;
import java.util.List;
import java.util.Map;

/**
 * Open Feign 接口调用客户端
 *
 * @author chendd
 * @date 2023/1/8 20:38
 */
@FeignClient(name = "chendd-nacos-client" , path = "/nacos-client/hello")
public interface OpenFeignClient {

    /**
     * 获取数据列表
     * @return 数据列表
     */
    @GetMapping(value = "/list")
    List<Point> getList();

    /**
     * 获取复杂数据对象
     * @return 复杂数据对象
     */
    @GetMapping(value = "/complex" , produces = MediaType.APPLICATION_JSON_VALUE)
    ComplexVo getComplex();

    /**
     * Hello world
     * @param name 名称
     * @return hello world
     */
    @GetMapping("/world/{name}")
    String sayHello(@PathVariable(name = "name") String name);

    /**
     * Hello world
     * @param name 参数名
     * @param value 参数值
     * @param author header参数值
     * @return hello 多个参数
     */
    @PostMapping(value = "/form" , consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    String sayHello(@RequestParam(name = "name") String name ,
                    @RequestParam(name = "value") String value ,
                    @RequestHeader(name = "author") String author);

    /**
     * 传递参数包含body和普通参数
     * @param name 普通参数
     * @param body body参数
     * @return 字符串
     */
    @PutMapping(value = "/param_body" , consumes = MediaType.APPLICATION_JSON_VALUE)
    String paramBody(@RequestParam(name = "name") String name , @RequestBody String body);

    /**
     * 下载yaml文本文件
     * @return response
     */
    @PostMapping(value = "/download_yaml" , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    Response downloadYaml();

    /**
     * 下载图片文件
     * @return response
     */
    @GetMapping(value = "/download_image" , produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    Response downloadImage();

    /**
     * 多文件上传（附带其它参数）
     * @param files 多文件
     * @param id 参数对象
     * @param name 参数对象
     * @param nikeNames 参数对象
     * @return 上传结果
     */
    @PostMapping(value = "/upload" , consumes = MediaType.MULTIPART_FORM_DATA_VALUE , produces = MediaType.APPLICATION_JSON_VALUE)
    Map<String , Object> upload(@RequestPart(value = "files") List<MultipartFile> files ,
                                @RequestParam(name = "id") Integer id,
                                @RequestParam(name = "name") String name,
                                @RequestParam(name = "nikeNames") List<String> nikeNames);

}
